#!/bin/bash

# 定义变量
SERVICE_URL="http://127.0.0.1:50000"
REGISTRY_ENDPOINT="/actuator/service-registry?status=DOWN"
SHUTDOWN_ENDPOINT="/actuator/shutdown"
WAIT_TIME=30

# 函数：检查上一步命令是否成功执行
check_status() {
    if [ $? -ne 0 ]; then
        echo "Error: Failed to execute the previous command."
        exit 1
    fi
}

# 发送请求关闭服务注册
curl -X POST "$SERVICE_URL$REGISTRY_ENDPOINT" -H 'Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8'
# check_status

# 等待一段时间
sleep $WAIT_TIME

# 发送请求关闭服务
curl -X POST "$SERVICE_URL$SHUTDOWN_ENDPOINT"
# check_status

echo "Service shutdown request sent successfully."
